<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.name" placeholder="内容"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="LogininfoQuery">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>

        <!--<el-form-item>
          &lt;!&ndash; 默认name="file" &ndash;&gt;
          <el-upload class="upload-demo"
                     action="http://localhost:8080/shop/importExcel"
                     list-type="text">
            <el-button type="warning">点击导入</el-button>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="success" @click="handleExport">导出</el-button>
        </el-form-item>-->
        
      </el-form>
		</el-col>

		<!--列表-->
		<template>
      <!--@selection-change="selsChange"选项改变会触发这个函数-->
      <el-table :data="logininfos"  highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
        <!-- type="selection"选项 -->
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column type="index" width="60">
        </el-table-column>
        <el-table-column  align="center" prop="username" label="名称" width="80" sortable>
        </el-table-column>
        <el-table-column align="center" prop="phone" label="电话" width="120" sortable>
        </el-table-column>
        <el-table-column align="center" prop="email" label="邮箱" width="110" sortable>
        </el-table-column>
        <el-table-column align="center" prop="salt" label="盐值" width="100"  sortable>
        </el-table-column>
        <el-table-column align="center"  prop="password" label="密码" width="120" sortable>
        </el-table-column>

        <el-table-column align="center"  prop="type" label="类型" width="80" sortable>
          <!--<el-radio-group v-model="editForm.type">
            <el-radio class="radio" :label="1">1</el-radio>
            <el-radio class="radio" :label="0">0</el-radio>
          </el-radio-group>-->
        </el-table-column>

        <el-table-column align="center"  prop="disable" label="是否有效" width="80" sortable>
          <!--<el-radio-group v-model="editForm.disable">
            <el-radio class="radio" :label="1">true</el-radio>
            <el-radio class="radio" :label="0">false</el-radio>
          </el-radio-group>-->
          <template slot-scope="scope">
            <span v-if="scope.row.disable==0" style="color: orange">false</span>
            <span v-if="scope.row.disable==1" style="color: blue">true</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="200">
          <template scope="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
            <!-- elmentUi提供的按钮：size表示大小，type表示按钮颜色
        	scope.$index：当前行下标   scope.row：当前行对象 -->
            <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
            <!--<el-button type="warning" :disabled="scope.row.state!==1" size="small"
                       @click="handleAudit(scope.$index, scope.row)">店铺审核</el-button>-->
          </template>
        </el-table-column>

      </el-table>
		</template>

    <!--工具条 批量删除-->
    <el-col :span="24" class="toolbar">
      <!--
        :disabled="this.sels.length===0" - 当选中的条数为0就禁用
        @click="batchRemove" - 单击事件调用batchRemove方法
      -->
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination layout="prev, pager, next"
                     @current-change="currentChange"
                     :page-size="pageSize"
                     :total="totals"
                     :current-page="currentPage"
                     style="float:right;">
      </el-pagination>
    </el-col>

    <!-- 审核模态框
    <el-dialog title="审核店铺" :visible.sync="shopAuditVisible" :close-on-click-modal="false">
      <el-form :model="shopAuditLog" label-width="80px"  ref="shopAuditLogForm">
        <el-form-item label="备注" prop="note">
          <el-input type="textarea" v-model="shopAuditLog.note"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="shopAuditVisible = false">取消</el-button>
        <el-button type="primary" @click.native="auditPass">通过</el-button>
        <el-button type="primary" @click.native="auditReject">驳回</el-button>
      </div>
    </el-dialog>
-->

    <!--编辑界面 模态框-->
    <el-dialog :title="title" :visible.sync="editFormVisible" :close-on-click-modal="false">
      <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">

        <el-form-item label="名称" prop="username">
          <el-input v-model="editForm.username" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="editForm.phone" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">
          <el-input v-model="editForm.email" auto-complete="off"></el-input>
        </el-form-item>
       <!-- <el-form-item label="盐值" prop="salt">
          <el-input v-model="editForm.salt" auto-complete="off"></el-input>
        </el-form-item>-->
        <el-form-item label="密码" prop="password">
          <el-input v-model="editForm.password" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item label="类型" prop="type">
          <el-radio-group v-model="editForm.type">
            <el-radio class="radio" :label="0">0</el-radio>
            <el-radio class="radio" :label="1">1</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="类型" prop="disable">
          <el-radio-group v-model="editForm.disable">
            <el-radio class="radio" :label="0">false</el-radio>
            <el-radio class="radio" :label="1">true</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="editFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
      </div>
    </el-dialog>

	</section>
</template>

<script>
export default {
  data() {
    return {

      filters: {
        name: ''
      },

      logininfos: [],
      //分页查询 - 总数量 - 计算分页栏
      totals: 0,
      //分页查询 - 当前页 - 计算分页栏
      currentPage: 1,
      //分页查询 - 每页显示的条数 - 分页栏显示页数
      pageSize: 5,

      listLoading: false,

      keywords:[],

      sels: [],//列表选中列


      //添加或修改数据
      title:"",

      editFormVisible: false,//编辑界面是否显示
      editLoading: false,

     /* //审核模态框
      shopAuditVisible: false,
      //编辑界面数据
      shopAuditLog: {
        shopId: null,
        note:''
      },*/



      //校验规则
      editFormRules: {
        phone: [
          { required: true, message: '请输入电话', trigger: 'blur' }
        ],
        username: [
          { required: true, message: '请输入名称', trigger: 'blur' }
        ]
      },
      //编辑界面数据
      editForm: {

        username: '',
        phone:null,
        email:null,
        salt: null,
        password:null,
        type:0,
        disable: false

      }
    }
  },
  methods: {

    //导出
    /*handleExport(){
    //直接发送请求
      location.href="http://localhost:8080/shop/export";
    },*/

   /* //审核驳回
    auditReject(){
      this.$http.post("/shop/audit/reject",this.shopAuditLog).then(res=>{
        if(res.data.success){
          this.$message({
            message: '驳回成功',
            type: 'success'
          });
        }else{
          this.$message({
            message: '驳回失败',
            type: 'error'
          });
        }
        this.shopAuditVisible = false;
        this.getLogininfos();
      })
    },
    //审核通过
    auditPass(){
      this.$http.post("/shop/audit/pass",this.shopAuditLog).then(res=>{

        if(res.data.success){
          this.$message({
            message: '审核通过',
            type: 'success'
          });
        }else{
          this.$message({
            message: '审核失败',
            type: 'error'
          });
        }
        this.shopAuditVisible = false;
        this.getLogininfos();
      })
    },
*/

    //高级查询的查询按钮绑定事件 跳转到第一页开始查询
    LogininfoQuery(){
      this.currentPage = 1;
      this.getLogininfos();
    },


    //点击实现分页查询方法
    currentChange(currentPage) {
      this.currentPage = currentPage;
      this.getLogininfos();

    },
/****************************************************/
    //获取店铺列表
    getLogininfos() {
      let para = {
        currentPage: this.currentPage,
        pageSize:this.pageSize,
        //高级查询参数 - 关键字
        keywords: this.filters.name
      };
      //开启忙等框
      this.listLoading = true;
      //发送请求
      this.$http.post("/logininfo",para)
          .then(res=>{
            //发送成功
            this.totals=res.data.totals;
            this.logininfos=res.data.data;
            //关闭忙等框
            this.listLoading = false;

          }).catch(res=>{
        this.$message.error("系统繁忙，请稍后重试！！")
      })

    },

    //点击店铺审核弹出模态框
    /*handleAudit: function (index, row) {
      //对shop_id赋值
      this.shopAuditLog.shop_id = row.id;
      this.shopAuditVisible = true;
    },*/


    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '温馨提示', {
        type: 'warning'
      }).then(() => {
        //开启忙等框
        this.listLoading = true;
        this.$http.delete("/logininfo/"+row.id)
            .then(res=>{
              //关闭忙等框
              this.listLoading = false;
              if(res.data.success){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else {
                this.$message({
                  message: res.data.msg,
                  type: 'error'
                });
              }
              //刷新页面之前跳转到第一页
              this.currentPage=1;
              //刷新页面
              this.getLogininfos();
            }).catch(res=>{
              this.$message({
                message: "系统繁忙，请稍后重试！！",
                type: 'error'
              });
             })
      }).catch(() => {
      });
    },


    //编辑
    //显示编辑界面
    handleEdit: function (index, row) {
      //弹出模态框
      this.editFormVisible = true;

      this.title="编辑";
      // 克隆  回显数据
      this.editForm = Object.assign({}, row);
    },


    //显示新增界面
    handleAdd: function () {
      //点击添加 弹出模态框
      this.editFormVisible = true;

      this.title="新增";
      //清空模态框操作
      this.editForm = {
        username: '',
        phone:null,
        email:null,
        salt: null,
        password:null,
        type:0,
        disable: false
      };

    },

    //点击提交按钮 发送请求
    editSubmit: function () {
      //表单校验
      this.$refs.editForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            //关开启忙等框
            this.editLoading = true;
            //克隆数据
            let para = Object.assign({}, this.editForm);

            //发送请求
            this.$http.put("/logininfo",para)
                .then(res=>{
                  //关闭忙等框
                  this.editLoading = false;
                  //关闭模态框
                  this.editFormVisible = false;
                  if(res.data.success){
                    this.$message({
                      message: '操作成功！',
                      type: 'success'
                    });
                  }else {
                    this.$message({
                      message: res.data.msg,
                      type: 'error'
                    });
                  }
                  //刷新页面
                  this.getLogininfos();
                }).catch(res=>{
                  this.$message({
                    message: "系统繁忙，请稍后重试！！",
                    type: 'error'
                  });
                  //刷新
                 this.getLogininfos();

                })

          });
        }
      });
    },



    //批量删除的参数
    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id)//id组成的数组[1,2,3,4]
      this.$confirm('确认删除选中记录吗？', '温馨提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        this.$http.patch("/logininfo",ids)
            .then(res=>{
              //关闭忙等框
              this.listLoading = true;
              if(res.data.success){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else {
                this.$message({
                  message: res.data.msg,
                  type: 'error'
                });
              }
              //操作完 跳转到第一页并刷新
              this.currentPage=1;
              this.getLogininfos();

            }).catch(res=>{
                this.$message({
                  message: "系统繁忙，请稍后重试！！",
                  type: 'error'
                });
            })
      }).catch(() => {

      });
    }
  },

  mounted() {
    this.getLogininfos();
  }
}

</script>

<style scoped>

</style>